package com.vdong.trade.trading.service.dubbo;

import com.alibaba.fastjson.JSON;
import com.vdong.trade.trading.common.contract.AbstractResponse;
import com.vdong.trade.trading.entity.dto.param.PaymentRequestDTO;
import com.vdong.trade.trading.entity.mo.WechatPayDataExampleMo;
import com.vdong.trade.trading.entity.mo.WechatPayDataMo;
import com.vdong.trade.trading.facade.TransactionPayFacade;
import com.vdong.trade.trading.respository.WechatPayDataMapper;
import com.vdong.trade.trading.service.TransactionPayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.lamb.framework.common.remote.FacadeResult;
import org.lamb.framework.common.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author <a href="mailto:clf@vdongzc.com">clf</a>
 * @Description: 支付FacadeImpl
 * @Date Create on 2018-12-13 15:10:22
 * @since version1.0
 */
@Service
@com.alibaba.dubbo.config.annotation.Service
@Slf4j
public class TransactionPayFacadeImpl implements TransactionPayFacade {

    @Autowired
    private TransactionPayService transactionPayService;

    @Override
    public FacadeResult<String> execPay(String request) throws Exception {
        log.info("========execPay入参为：[{}]", JSON.toJSONString(request));
        PaymentRequestDTO paymentRequest = JSON.parseObject(request, PaymentRequestDTO.class);
        FacadeResult<AbstractResponse> result = transactionPayService.execPay(paymentRequest);
        if (result.isSuccess()) {
            return FacadeResult.buildSucc(JSON.toJSONString(result.getData()));
        } else {
            return FacadeResult.buildFail(result.getErrorMsg());
        }
    }

    @Override
    public String queryOrder(String request) throws Exception {
        return JSON.toJSONString(transactionPayService.queryOrder(request, false));
    }

    @Override
    public String queryWaitAsyncNotifyOrder(String request) throws Exception {
        return JSON.toJSONString(transactionPayService.queryOrder(request, true));

    }

}
